/* 
 * File:   driver_i2c.h
 * Author: Ich
 *
 * Created on 23.02.2014, 16:03
 *
 * Description:
 * Driver for I2C-Interface.
 */

#ifndef DRIVER_I2C_H
#define	DRIVER_I2C_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <GenericTypeDefs.h>
#include <plib.h>
/*******************************************************************************
 *  public preprocessing definitions
 */
    
 /*******************************************************************************
 *  public variables
 */

/*******************************************************************************
 *  public functions
 */

 /* Initialises the I2C-Bus with the specific speed.
 *
 * param(in)    module      which module I2C1...I2C5
 * param(in)    clkSpeed    [Hz] speed of CLK-Signal.
  *
  * return      successful  true = ok, false = error
 *
 */
BOOL drvI2C_init(I2C_MODULE module, UINT32 clkSpeed);

/* This is a blocking routine that waits for the Stop signal to complete.
 *
 * param(in)    module      which module I2C1...I2C5
 * param(in)    slaveAddr   7-bit-address of slave device
 * param(in)    pSlaveRegAddr address of slave device register
 * param(in)    slaveRegLen length of slave register
 * param(in)    pData       pointer to write data
 * param(in)    dataLen     length of write data
 *
 * return       successful  true = ok, false = error.
 *
 */
BOOL drvI2C_write(I2C_MODULE module, I2C_7_BIT_ADDRESS slaveAddr, UINT8 *pSlaveRegAddr, UINT8 slaveRegLen, UINT8 *pData, UINT8 dataLen);

/* This is a blocking routine that waits for the Stop signal to complete.
 * Writes only a byte.
 *
 * param(in)    module      which module I2C1...I2C5
 * param(in)    slaveAddr   7-bit-address of slave device
 * param(in)    slaveRegAddr address of slave device register
 * param(in)    data        data to write
 *
 * return       successful  true = ok, false = error.
 *
 */
BOOL drvI2C_writeByte(I2C_MODULE module, I2C_7_BIT_ADDRESS slaveAddr, UINT8 slaveRegAddr, UINT8 data);

/* This is a blocking routine that waits for the Stop signal to complete.
 *
 * param(in)    module      which module I2C1...I2C5
 * param(in)    slaveAddr   7-bit-address of slave device
 * param(in)    pSlaveRegAddr address of slave device register
 * param(in)    slaveRegLen length of slave register
 * param(in)    pData       pointer to received data
 * param(in)    dataLen     number of data to read
 *
 * return       successful  true = ok, false = error.
 *
 */
BOOL drvI2C_read(I2C_MODULE module, I2C_7_BIT_ADDRESS slaveAddr, UINT8 *pSlaveRegAddr, UINT8 slaveRegLen, UINT8 *pData, UINT8 dataLen);

/* This is a blocking routine that waits for the Stop signal to complete.
 * Reads only 1 Byte.
 *
 * param(in)    module      which module I2C1...I2C5
 * param(in)    slaveAddr   7-bit-address of slave device
 * param(in)    slaveRegAddr address of slave device register
 * param(in)    pData       pointer to received data
 *
 * return       successful  true = ok, false = error.
 *
 */
BOOL drvI2C_readByte(I2C_MODULE module, I2C_7_BIT_ADDRESS slaveAddr, UINT8 slaveRegAddr, UINT8 *pData);

#ifdef	__cplusplus
}
#endif

#endif	/* DRIVER_I2C_H */


